home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / instal.zip / WSLIB / DOS.ASM < prev    next >
Assembly Source File  |  1990-07-04  |  13KB  |  391 lines

  1. ;****************************************************************************
  2. ;*                                                                          *
  3. ;*  WFDOSDIR.ASM -                                                          *
  4. ;*                                                                          *
  5. ;*      Directory searching primitives                                      *
  6. ;*                                                                          *
  7. ;****************************************************************************
  8.  
  9. ?PLM=1      ; PASCAL Calling convention is DEFAULT
  10. ?WIN=1      ; Windows calling convention
  11. ?386=0      ; Use 386 code?
  12.  
  13. include cmacros.inc
  14.  
  15. ; The following structure should be used to access high and low
  16. ; words of a DWORD.  This means that "word ptr foo[2]" -> "foo.hi".
  17.  
  18. LONG    struc
  19. lo      dw      ?
  20. hi      dw      ?
  21. LONG    ends
  22.  
  23. FARPOINTER      struc
  24. off     dw      ?
  25. sel     dw      ?
  26. FARPOINTER      ends
  27.  
  28. ifndef SEGNAME
  29.     SEGNAME equ <TEXT>
  30. endif
  31.  
  32. if ?386
  33.     createSeg _%SEGNAME, CodeSeg, word, use16, CODE
  34. else
  35.     createSeg _%SEGNAME, CodeSeg, word, public, CODE
  36. endif
  37.  
  38. NOT_SUPPORTED     =  2h      ; Return code from IsDeviceRemote function.
  39. REMOTE            =  3h      ; Return code for remote drive found.
  40. TRUE              =  1h      ; TRUE Definition
  41. FALSE             =  0h      ; False Definition.
  42.  
  43. ;=============================================================================
  44.  
  45. sBegin DATA
  46.  
  47. VolExtendedFCB  db  0FFh
  48.                 db  0, 0, 0, 0, 0
  49.                 db  1000b
  50.                 db  0
  51.                 db  11 dup('?')
  52.                 db  5 dup(0)
  53.                 db  11 dup('?')
  54.                 db  9 dup(0)
  55.  
  56. DTA             db  64 dup(0)
  57.  
  58. sEnd   DATA
  59.  
  60. ;=============================================================================
  61.  
  62. sBegin CodeSeg
  63.  
  64. assumes CS,CodeSeg
  65. assumes DS,DATA
  66.  
  67. ;*--------------------------------------------------------------------------*
  68. ;*                                                                          *
  69. ;*  DosFindFirst() -                                                        *
  70. ;*                                                                          *
  71. ;*--------------------------------------------------------------------------*
  72.  
  73. ; Get the first directory entry.
  74.  
  75. cProc DosFindFirst, <FAR, PUBLIC>
  76.  
  77. ParmD lpDest
  78. ParmD szFileSpec
  79. ParmW attrib
  80.  
  81. cBegin
  82.             push    ds
  83.             lds     dx,lpDest
  84.             mov     ah,1Ah          ; Set DTA
  85.             int     21h
  86.  
  87.             mov     cx,attrib       ; Find First File
  88.             lds     dx,szFileSpec   ; Path = szFileSpec
  89.             mov     ah,4Eh
  90.             int     21h
  91.             jc      fferr
  92.             mov     ax,1
  93.             jmp     short ffdone
  94.  
  95. fferr:
  96.             xor     ax,ax           ; Return zero on error
  97. ffdone:
  98.             pop     ds
  99. cEnd
  100.  
  101.  
  102. ;*--------------------------------------------------------------------------*
  103. ;*                                                                          *
  104. ;*  DosFindNext() -                                                         *
  105. ;*                                                                          *
  106. ;*--------------------------------------------------------------------------*
  107.  
  108. cProc DosFindNext, <FAR, PUBLIC>
  109.  
  110. ParmD lpDest
  111.  
  112. cBegin
  113.             push    ds
  114.             lds     dx,lpDest
  115.             mov     ah,1Ah          ; Set DTA
  116.             int     21h
  117.             pop     ds
  118.  
  119.             les     bx,lpDest       ; ES:BX = lpDest
  120.             mov     ah,4Fh          ; Find Next File
  121.             int     21h
  122.             mov     ax,1
  123.             jnc     FNExit          ; Exit if no error
  124. FNErr:
  125.             xor     ax,ax           ; Return FALSE
  126. FNExit:
  127. cEnd
  128.  
  129. ;*--------------------------------------------------------------------------*
  130. ;*                                                                          *
  131. ;*  DosMkDir()                                                              *
  132. ;*                                                                          *
  133. ;*--------------------------------------------------------------------------*
  134.  
  135. cProc DosMkDir, <FAR, PUBLIC>
  136. ParmD   szDir
  137. cBegin
  138.         lds     dx,szDir
  139.         mov     ah,39h
  140.         int     21h
  141.         jc      mderror
  142.         xor     ax,ax
  143.         jmp     short mdexit
  144.  
  145. mderror:
  146.         mov     ah,59h
  147.         xor     bx,bx
  148.         int     21h
  149.  
  150. mdexit:
  151.  
  152. cEnd
  153.  
  154. ;*--------------------------------------------------------------------------*
  155. ;*                                                                          *
  156. ;*  MyReadWriteSector() -                                                   *
  157. ;*                                                                          *
  158. ;*--------------------------------------------------------------------------*
  159.  
  160. ; Uses INT 13h to read/write an absolute sector.
  161.  
  162. cProc MyReadWriteSector, <PUBLIC, FAR>, <SI,DI>
  163.  
  164. ParmD   lpBuffer
  165. ParmW   Function                       ; 02 for Read and 03 for Write
  166. ParmW   Drive
  167. ParmW   Cylinder
  168. ParmW   Head
  169. ParmW   Count
  170.  
  171. LocalW  wRetryCount 
  172.  
  173. cBegin
  174.         ; Retry this operation three times.
  175.         mov     wRetryCount,4
  176.  
  177. MRWS_TryAgain:
  178.         mov     ax,Count                ; AL = Number of sectors
  179.         mov     ah,byte ptr Function    ; AH = Function #
  180.         mov     ch,byte ptr Cylinder    ; CH = Starting Cylinder
  181.         mov     cl,1                    ; CL = Starting Sector
  182.  
  183.         mov     dx,Drive        ; DL = INT 13h drive designation
  184.  
  185.         mov     dh,byte ptr Head        ; DH = Head #
  186.         les     bx,lpBuffer             ; ES:BX = Buffer
  187.         int     13h
  188.         
  189.         mov     ax, 1                   ; success
  190.  
  191.         jnc     MRWS_End_success        ; Problems?
  192.         dec     wRetryCount             ; Yup, retry
  193.         jz      MRWS_End_fail           ; Are we out of retries?
  194.  
  195.         xor     ah,ah                   ; Nope, reset the disk
  196.         mov     dx,Drive
  197.         int     13h
  198.         jmp     short MRWS_TryAgain
  199. MRWS_End_fail:
  200.         xor     al,al           ; AH contains the error code, if any.
  201. MRWS_End_success:
  202.  
  203. cEnd
  204.  
  205. ;*--------------------------------------------------------------------------*
  206. ;*                                                                          *
  207. ;*  GetCurrentDrive() -                                                     *
  208. ;*                                                                          *
  209. ;*--------------------------------------------------------------------------*
  210.  
  211. cProc GetCurrentDrive, <FAR, PUBLIC>
  212.  
  213. cBegin
  214.         mov     ah,19h              ; Get Current Drive
  215.         int     21h
  216.         sub     ah,ah               ; Zero out AH
  217. cEnd
  218.  
  219. ;*--------------------------------------------------------------------------*
  220. ;*                                                                          *
  221. ;*  GetCurrentDirectory() -                                                 *
  222. ;*                                                                          *
  223. ;*--------------------------------------------------------------------------*
  224.  
  225. cProc DosCwd, <FAR, PUBLIC>, <SI, DI>
  226.  
  227. ParmD lpDest
  228.  
  229. cBegin
  230.             push    ds                  ; Preserve DS
  231.  
  232.             call    GetCurrentDrive
  233.             mov     si,ax               ; SI = Current drive
  234.  
  235.             les     di,lpDest           ; ES:DI = lpDest
  236.             push    es
  237.             pop     ds                  ; DS:DI = lpDest
  238.             cld
  239.             mov     ax,si               ; AX = Current drive
  240.             inc     al                  ; Convert to logical drive number
  241.             mov     dl,al               ; DL = Logical Drive Number
  242.             add     al,'@'              ; Convert to ASCII drive letter
  243.             stosb
  244.             mov     al,':'
  245.             stosb
  246.             mov     al,'\'              ; Start string with a backslash
  247.             stosb
  248.             mov     byte ptr es:[di],0  ; Null terminate in case of error
  249.             mov     si,di               ; DS:SI = lpDest[1]
  250.             mov     ah,47h              ; Get Current Directory
  251.             int     21h
  252.             jc      CDExit              ; Skip if error
  253.             xor     ax,ax               ; Return FALSE if no error
  254. CDExit:
  255.             pop     ds                  ; Restore DS
  256. cEnd
  257.  
  258. ;*--------------------------------------------------------------------------*
  259. ;*                                                                          *
  260. ;*  SetCurrentDrive() -                                                     *
  261. ;*                                                                          *
  262. ;*--------------------------------------------------------------------------*
  263.  
  264. ; Returns the number of drives in AX.
  265.  
  266. cProc SetCurrentDrive, <FAR, PUBLIC>
  267.  
  268. ParmW Drive
  269.  
  270. cBegin
  271.             mov     dx,Drive
  272.             mov     ah,0Eh              ; Set Current Drive
  273.             int     21h
  274.             sub     ah,ah               ; Zero out AH
  275. cEnd
  276.  
  277. ;*--------------------------------------------------------------------------*
  278. ;*                                                                          *
  279. ;*  SetCurrentDirectory() -                                                 *
  280. ;*                                                                          *
  281. ;*--------------------------------------------------------------------------*
  282.  
  283. cProc DosChDir, <FAR, PUBLIC>
  284.  
  285. ParmD lpDirName
  286.  
  287. cBegin
  288.             push    ds                  ; Preserve DS
  289.             lds     dx,lpDirName        ; DS:DX = lpDirName
  290.  
  291.             mov     bx,dx
  292.             mov     ax,ds:[bx]
  293.             cmp     ah,':'
  294.             jnz     cdnodrive
  295.  
  296.             ;
  297.             ;       Convert drive letter to drive index
  298.             ;
  299.             or      al,20h
  300.             sub     al,'a'
  301.             xor     ah,ah
  302.  
  303.             push    dx
  304.             cCall   SetCurrentDrive,<ax>
  305.             pop     dx
  306. cdnodrive:
  307.             mov     ah,3Bh              ; Change Current Directory
  308.             int     21h
  309.             jc      SCDExit             ; Skip on error
  310.             xor     ax,ax               ; Return FALSE if successful
  311. SCDExit:
  312.             pop     ds                  ; Restore DS
  313. cEnd
  314.  
  315. ;*--------------------------------------------------------------------------*
  316. ;*                                                                          *
  317. ;*  DosValidDir()                                                           *
  318. ;*                                                                          *
  319. ;*--------------------------------------------------------------------------*
  320.  
  321. cProc DosValidDir, <FAR, PUBLIC>, <SI, DI>
  322. ParmD       szDir
  323. LocalV      szCwd, 128
  324. cBegin
  325.     lea     si,szCwd
  326.     cCall   DosCwd,<ss,si>
  327.     push    szDir.sel
  328.     push    szDir.off
  329.     call    DosChDir
  330.     or      ax,ax
  331.     pushf
  332.     cCall   DosChDir,<ss,si>
  333.     ;
  334.     ;   return TRUE if DosChdir returns 0, FALSE otherwise
  335.     ;
  336.     xor     ax,ax                ; don't care about this return val.
  337.     popf
  338.     jnz     vdexit
  339.     inc     ax
  340. vdexit:
  341.  
  342. cEnd
  343.  
  344. ;*--------------------------------------------------------------------------
  345. ;*
  346. ;*  LONG DosDiskFreeSpace(Drive)
  347. ;*
  348. ;*  note:
  349. ;*      Drive == 0      default
  350. ;*      Drive == 1      A
  351. ;*      Drive == 2      B
  352. ;*--------------------------------------------------------------------------
  353.  
  354. ; Returns the number of bytes free in DX:AX
  355.  
  356. cProc DosDiskFreeSpace, <FAR, PUBLIC>
  357. ParmW Drive
  358. cBegin
  359.             mov     dx,Drive
  360.             mov     ah,36h              ; Set Current Drive
  361.             int     21h
  362.             cmp     ax, 0ffffh          ; bogus drive?
  363.             je      error
  364.             mul     cx                  ;
  365.             mul     bx
  366.             jmp     done                ; DX:AX contains free space
  367. error:
  368.             mov     dx, ax              ; return dx:ax = -1L
  369. done:
  370. cEnd
  371.  
  372. ;*--------------------------------------------------------------------------*
  373. ;*                                                                          *
  374. ;*  DosExit(ec);                                                            *
  375. ;*                                                                          *
  376. ;*  Terminate program                                                       *
  377. ;*                                                                          *
  378. ;*--------------------------------------------------------------------------*
  379.  
  380. cProc DosExit, <FAR, PUBLIC>
  381. ParmW   ec
  382. cBegin
  383.         mov     al,byte ptr ec
  384.         mov     ah,4Ch
  385.         int     21h
  386. cEnd
  387.  
  388. sEnd CodeSeg
  389.  
  390. end
  391.